package com.hxd.otc.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxd.otc.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/8/28 0028.
 * description ${我的界面条目}
 */
public class MyItemView extends ConstraintLayout {
    @BindView(R.id.tv_right)
    TextView mTvRight;
    @BindView(R.id.iv_tag)
    ImageView mIvTag;
    @BindView(R.id.tv_left)
    TextView mTvLeft;

    public MyItemView(Context context) {
        this(context, null);
    }

    public MyItemView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyItemView, defStyleAttr, 0);
        CharSequence leftText = a.getText(R.styleable.MyItemView_leftText);
        CharSequence rightText = a.getText(R.styleable.MyItemView_rightText);
        Drawable lefDrawable = a.getDrawable(R.styleable.MyItemView_leftIcon);
        Drawable tagDrawable = a.getDrawable(R.styleable.MyItemView_tagIcon);
        a.recycle();

        LayoutInflater.from(context).inflate(R.layout.view_my_item, this);
        ButterKnife.bind(this);

        setLeftText(leftText);
        setRightText(rightText);
        setLeftDrawable(lefDrawable);
        if (tagDrawable != null) {
            setTagDrawable(tagDrawable);
        }
    }

    public void setLeftText(CharSequence leftText) {
        mTvLeft.setText(leftText);
    }

    public void setRightText(CharSequence rightText) {
        mTvRight.setText(rightText);
    }

    public void setLeftDrawable(Drawable drawable) {
        mTvLeft.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
    }

    public void setTagDrawable(Drawable tagDrawable) {
        mIvTag.setImageDrawable(tagDrawable);
    }

    public void setTagVisibility(int visibility) {
        mIvTag.setVisibility(visibility);
    }

    public int getTagVisibility() {
        return mIvTag.getVisibility();
    }
}
